#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
using namespace std;
class Solution {
public:
    bool isMatch(string s, string p) {
        bool dp[1500][1500];
        memset(dp, 0, sizeof dp);
        dp[0][0] = 1;
        for (int i = 0; i < p.length(); i++)
        {
            if (p[i] == '*')
            {
                dp[0][i + 1] = dp[0][i];
            }
            else
            {
                dp[0][i + 1] = 0;
            }
        }
        for (int i = 0; i < s.length(); i++)
        {
            for (int j = 0; j < p.length(); j++)
            {
                if (s[i] == p[j] || p[j] == '?')
                {
                    dp[i + 1][j + 1] = dp[i][j];
                    continue;
                }
                if (p[j] == '*')
                {

                    dp[i + 1][j + 1] = (dp[i + 1][j] || dp[i][j + 1]);
                    continue;

                }
            }
        }
        return dp[s.length()][p.length()];
    }
};
int main()
{
    Solution s;
    string ss = "aa", pp = "a";
    while (cin >> ss >> pp)
        if (s.isMatch(ss, pp))
            cout << 1 << endl;
        else
            cout << 0 << endl;
}